unit uTesteDll_NF;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Formulario_Padrao_Rel, RDprint, ExtCtrls, StdCtrls, CheckLst,
  ComCtrls, TFlatButtonUnit, Buttons, Spin;

type
  TfrmtesteDLL = class(TFrmPad_Rel)
    rgLPP: TRadioGroup;
    rgCPP: TRadioGroup;
    GroupBox1: TGroupBox;
    edQtdLin: TSpinEdit;
    edQtdCol: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure rgLPPClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btncancelarClick(Sender: TObject);
    procedure bimprimirClick(Sender: TObject);
  private
    { Private declarations }
    procedure ImprimeArquivo;
  public
    { Public declarations }
  end;

var
  frmtesteDLL: TfrmtesteDLL;

implementation

uses Biblio_Imp, Biblio;

{$R *.dfm}

procedure TfrmtesteDLL.rgLPPClick(Sender: TObject);
begin
  inherited;
  if rgLPP.ItemIndex = 0 then
    edQtdLin.Value := 66
  else
    edQtdLin.Value := 88;
end;

procedure TfrmtesteDLL.FormActivate(Sender: TObject);
begin
  inherited;
  rgLPP.ItemIndex := 0;
  rgCPP.ItemIndex := 1;
  edQtdLin.Value := 66;
  edQtdCol.Value := 80;
  rgLPP.SetFocus;
end;

procedure TfrmtesteDLL.btncancelarClick(Sender: TObject);
begin
  inherited;
  FormActivate(sender);
end;

procedure TfrmtesteDLL.bimprimirClick(Sender: TObject);
var
  lpp: Integer;
  fonte: Tfonte;
begin
  inherited;
  if rgLPP.ItemIndex = 0 then
    lpp := 6
  else
    lpp := 8;
  case rgCPP.ItemIndex of
    0: fonte := [expandido];
    1: fonte := [normal];
    2: fonte := [comp12];
    3: fonte := [comp17];
    4: fonte := [comp20];
  end;
  if rgLPP.ItemIndex <> 2 then
    Imprime_Matriz(iv(edQtdLin.Value), lpp, fonte)
  else
    ImprimeArquivo;
end;

procedure TfrmtesteDLL.ImprimeArquivo;
const
  cJustif = #27#97#51;
  cEject = #12;
var
  l, c, col: Integer;
  vet: array[1..100] of string;
  F: TextFile;
begin
  xNomeArqIMPRESSAO := '';
  AssignFile(F, 'LPT1');
  Rewrite(F);

  for l := 1 to iv(edQtdLin.Value) do begin
    for c := 1 to iv(edQtdCol.Value) do begin

      if l = 1 then begin
        if (l = 1) and (c = 1) then
          vet[1] := vet[1] + '1'
        else begin
          if ((c mod 5) = 0) and ((c mod 10) <> 0) then
            vet[1] := vet[1] + '.'
          else begin
            if (c mod 10) = 0 then begin
              if c < 100 then
                vet[1] := vet[1] + FloatToStr(c / 10)
              else begin
                vet[1] := copy(vet[1], 1, length(vet[1]) - 1);
                vet[1] := vet[1] + FloatToStr(c / 10);
              end;
            end else
              vet[1] := vet[1] + ' ';
          end;
        end;
      end else begin
        if (l = 2) then begin
          if c = 1 then
            vet[2] := '2'
          else begin
            if c < 100 then
              vet[2] := vet[2] + copy(StrZero(IntToStr(c), 2), 2, 1)
            else
              vet[2] := vet[2] + copy(StrZero(IntToStr(c), 3), 3, 1);
          end;
        end else begin
          if c = 1 then begin
            vet[l] := IntToStr(l);
          end else begin
            if ((l mod 5) = 0) and (c > 2) then begin
              if (c mod 5) = 0 then
                vet[l] := vet[l] + '+'
              else
                vet[l] := vet[l] + '-';
            end else begin
              if ((c mod 5) = 0) then
                vet[l] := vet[l] + '|'
              else
                vet[l] := vet[l] + ' ';
            end;
            if (l > 9) and (c = 3) then
              vet[l] := copy(vet[l], 1, length(vet[l]) - 1);
          end; //c=1
        end; //linha = 2
      end;
    end; //for col
  end; //for lin
  for l := 1 to iv(edQtdLin.Value) do
    Writeln(F, vet[l]);
  WriteLn(F, cEject);
  CloseFile(F);
end;

end.

